<!--#include file="..\CheckSession.inc"-->
<HEAD>
<META NAME="GENERATOR" Content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<%
	sSQl="select * from dangkylich"
	Set Rec=server.CreateObject("ADODB.Recordset")
	Rec.CursorType=3
	Rec.CacheSize=5
	Rec.Open sSQL,Conn
	do while not rec.eof	
		if Rec("tongcuc") then
			bttdv=1
		else
			bttdv=0
		end if
		Call Substring(TP,DD,ND,PT,Rec("noidung"))
		sql="insert into dklich(ngaydangky,noidung,thanhphan,diadiem,ttdv,macanbo) values ('"& SaveDate(FormatDate(Rec("idngay"))) &"','"& ND &"','"& TP &"','"& DD &"',"& bttdv &",'"& Rec("manhom") &"')"
		Conn.Execute sql
		response.write("Insert is OK ! <br>")
		rec.movenext
	loop
	Rec.close
	set Rec=nothing

	sSQl="select * from dangkylich where dstruc like 'ON'"
	Set Rec=server.CreateObject("ADODB.Recordset")
	Rec.CursorType=3
	Rec.CacheSize=5
	Rec.Open sSQL,Conn
	do while not rec.eof
		if Rec("tongcuc") then
			bttdv=1
		else
			bttdv=0
		end if
		sql="insert into dktruc(ngaydangky,tttruc,ttdv,macanbo) values ('"& SaveDate(FormatDate(Rec("idngay"))) &"',1,"& bttdv &",'"& Rec("manhom") &"')"
		Conn.Execute sql
		response.write("Insert is OK ! <br>")
		rec.movenext
	loop
	Rec.close
	set Rec=nothing

	sSQl="select * from lichtruc"
	Set Rec=server.CreateObject("ADODB.Recordset")
	Rec.CursorType=3
	Rec.CacheSize=5
	Rec.Open sSQL,Conn
	do while not rec.eof
		sql="insert into lichtrucn(ngaythang,cbtruc,madonvi) values ('"& SaveDate(FormatDate(Rec("ngay"))) &"','"& Rec("dscanbo") &"','"& trim(Rec("manhom")) &"')"
		Conn.Execute sql
		response.write("Insert is OK ! <br>")
		rec.movenext
	loop
	Rec.close
	set Rec=nothing

	sSQl="select * from lichct"
	Set Rec=server.CreateObject("ADODB.Recordset")
	Rec.CursorType=3
	Rec.CacheSize=5
	Rec.Open sSQL,Conn
	do while not rec.eof	
		Call Substring(TP,DD,ND,PT,Rec("viec"))
		sql="insert into lichcongtac(thoigian,thoigiankt,ngaythang,noidung,thanhphan,diadiem,madonvi) values ('','','"& SaveDate(FormatDate(Rec("ngay"))) &"','"& ND &"','"& TP &"','"& DD &"','"& trim(Rec("madonvi")) &"')"
		Conn.Execute sql
		response.write("Insert is OK ! <br>")
		rec.movenext
	loop
	Rec.close
	set Rec=nothing
%>
<Script Language=vbscript Runat=server>
	Function Substring1(ByRef Thanhphan, ByRef Diadiem, ByRef Noidung, ByVal bStr)
	    Dim bVTTP, bVTDD, bLen1, bLen2
	    bcat1 = "Thành phần:("
	    bcat2 = "Địa điểm:("
	    bVTTP = InStr(1, bStr, bcat1, vbBinaryCompare)
	    bVTDD = InStr(bVTTP, bStr, bcat2, vbBinaryCompare)
	    bLen1 = bVTDD - bVTTP - Len(bcat1) - 2
	    bLen2 = Len(bStr) - bVTDD - Len(bcat2)
	    Thanhphan = Mid(bStr, bVTTP + Len(bcat1), bLen1)
	    Diadiem = Mid(bStr, bVTDD + Len(bcat2), bLen2)
	    Noidung = Mid(bStr, 1, bVTTP - 1)
	End Function
	Function Substring(ByRef Thanhphan, ByRef Diadiem, ByRef Noidung, ByRef Phuongtien, ByVal bStr)
	    Dim bVTTP, bVTDD, bLen1, bLen2
	    bcat1 = "Thành phần:("
	    bcat2 = "Địa điểm:("
	    bcat3="Phương tiện:("
	    bVTTP = InStr(1, bStr, bcat1, vbBinaryCompare)
	    bVTDD = InStr(bVTTP, bStr, bcat2, vbBinaryCompare)
	    bVTPT=InStr(bVTDD, bStr, bcat3, vbBinaryCompare)
	    bLen1 = bVTDD - bVTTP - Len(bcat1) - 2
	    bLen2 = bVTPT - bVTDD - Len(bcat2)-2
	    bLen3=Len(bStr) - bVTPT - Len(bcat3)
	    Thanhphan = Mid(bStr, bVTTP + Len(bcat1), bLen1)
	    Diadiem = Mid(bStr, bVTDD + Len(bcat2), bLen2)
	    Phuongtien = Mid(bStr, bVTPT + Len(bcat3), bLen3)
	    Noidung = Mid(bStr, 1, bVTTP - 1)
	End Function
	Function FormatDate(vDate)
	   If Not IsNull(vDate) Then
	        vM = Right("0" & Month(vDate), 2)
	        vD = Right("0" & Day(vDate), 2)
	        vY = Right("19" & Year(vDate), 4)
	        FormatDate = vD & "/" & vM & "/" & vY
	   End If
	End Function
	Function SaveDate(vDate)
		dim bvitri1
		dim bvitri2
	   vDate=trim(cstr(vDate))
	   bvitri1=instr(1,vDate,"/")
	   bMonth=left(vDate,bvitri1-1)
	   bvitri2=instr(bvitri1+1,vDate,"/")
	   Dim Temp
	   Temp=right(vDate,len(vDate)-bvitri1)
	   bDay=left(Temp,bvitri2-bvitri1-1)
	   bYear=right(vDate,len(vDate)-bvitri2)
       SaveDate=bDay+"/"+bMonth+"/"+bYear
	End Function
</Script>
</HEAD>